<template>
  <div class="Lyric">
    <div class="container" ref="lyric">
      <div
        class="lyricItem"
        v-for="(item, index) in lyric"
        :key="index"
        :class="{
          highLight: (currentTime > lyric[index][0] && currentTime < lyric[index + 1][0]) || (currentTime > lyric[lyric.length - 2][0] && index === lyric.length - 2),
        }"
      >
        {{ item[1] }}{{ lyricScroll(index) }}
      </div>
    </div>
  </div>
</template>

<script>
import { mapGetters } from 'vuex';
export default {
  props: {
    lyric: {
      type: Array,
    },
  },
  data() {
    return {};
  },
  computed: {
    ...mapGetters(['currentTime']),
  },
  created() {},
  components: {},
  methods: {
    //歌词滚动
    lyricScroll(index) {
      if (this.currentTime > this.lyric[index][0] && this.currentTime < this.lyric[index + 1][0]) {
        //整体歌词到顶部的距离
        this.$refs.lyric.style.top = -(40 * (index - 3)) + 'px';
      }
      if (this.currentTime > this.lyric[this.lyric.length - 2][0]) {
        this.$refs.lyric.style.top = -(40 * (this.lyric.length - 4)) + 'px';
      }
    },
  },
};
</script>

<style scoped lang='scss'>
.Lyric {
  height: 350px;
  position: relative;
  overflow-y: scroll;
  &::-webkit-scrollbar {
    display: none;
  }
  .container {
    width: 100%;
    position: absolute;
    top: 0;
    transition: all 1s;
    .lyricItem {
      color: #666;
      height: 40px;
      line-height: 40px;
      @include hidWord;
    }
    .highLight {
      color: #000000;
      font-weight: 600;
    }
  }
}
</style>